default:
	@echo 'Usual make targets are:'
	@echo '  depes, compile, install, module, all'


# Install varnish dependencies.
deps:
	echo "You may need to \"sudo make deps\""
	apt-get -y install make
	apt-get -y install autotools-dev
	apt-get -y install automake
	apt-get -y install automake1.9
	apt-get -y install libtool
	apt-get -y install autoconf
	apt-get -y install libncurses-dev
	apt-get -y install groff-base
	apt-get -y install libpcre3-dev
	apt-get -y install pkg-config
	apt-get -y install python-docutils
	# Install redis.
	apt-get -y install redis-server

compile:
# Compile varnish.
	cd lib && \
	tar -xzf varnish-3.0.2.tar.gz
	cd lib/varnish-3.0.2/ && \
	./configure && \
	make
# Compile hiredis.
	cd lib && \
	tar -xzf antirez-hiredis-v0.10.1-29-g857b269.tar.gz
	cd lib/antirez-hiredis-857b269/ && \
	make
# Compile redis plugin.
	cd lib && \
	tar -xzf zephirworks-libvmod-redis-ef73a48.tar.gz
	cd lib/zephirworks-libvmod-redis-ef73a48/ && \
	./autogen.sh && \
	./configure VARNISHSRC=../varnish-3.0.2 && \
	make
# Compile mhash.
	cd lib && \
	tar -xjf mhash-0.9.9.9.tar.bz2
	cd lib/mhash-0.9.9.9/ && \
	./configure && \
	make
# Compile digest plugin.
	cd lib && \
	tar -xzf varnish-libvmod-digest-0.3-1-g6fa5034.tar.gz
	cd lib/varnish-libvmod-digest-6fa5034/ && \
	./autogen.sh && \
	./configure VARNISHSRC=../varnish-3.0.2 && \
	make

install:
	echo "You may need to \"sudo make install\""
	cd lib/varnish-3.0.2/ && make install
	cd lib/antirez-hiredis-857b269/ && make install
	cd lib/zephirworks-libvmod-redis-ef73a48/ && make install
	cd lib/mhash-0.9.9.9/ && make install
	cd lib/varnish-libvmod-digest-6fa5034/ && make install
# Install library so varnish can see it.
	ln -sf /usr/local/lib/libhiredis.so.0.10 /usr/local/lib/varnish/
	ln -sf /usr/local/lib/libmhash.so.2 /usr/local/lib/varnish/

# Copy vcl to varnish directory.
module:
	echo "You may need to \"sudo make module\""
	install -c vcl/varnish-apikey.vcl /etc/varnish/varnish-apikey.vcl

# Do everything
all: \
	deps \
	compile \
	install \
	module
